/*
 * Properties meta data of form components
 */

/*
 * ***********************************************************
 * DEFINE CONTAINERS HERE
 * ***********************************************************
*/

/**
 * layout - component for managing layout, containers for other elements
 * datacontrol - components for holding user data, input, textarea etc.
 * usercontrol - interactive components such as buttons, images, links
 */

function fmdf_initComponentMeta(fmd) {
	//component i18n
	fmd_i18n_modules = {};
	
	//all containers wrapper
	fmdmeta_prop = {};
	
	//lang
	fmdmeta_prop.lang = fmd.lang;
	fmdmeta_prop.elemAttachEnabled = fmd.elemAttachEnabled;

	//icon path
	fmdmeta_prop.iconpath = "/static/images/form/designer/prop/";

	//properties grid configuration
	fmdmeta_prop.gridconf = {};
	fmdmeta_prop.gridconf.isTreeGrid = true;
	//fmdmeta_prop.gridconf.treeIconPath = "/static/images/form/designer/prop/";
	fmdmeta_prop.gridconf.treeImagePath = "/static/css/dhtmlx4/imgs/";
	fmdmeta_prop.gridconf.extIconPath = "/static/images/form/designer/prop/";
	fmdmeta_prop.gridconf.header = [fmd_i18n_prop_prop,fmd_i18n_prop_value];
	//fmdmeta_prop.gridconf.subHeader;
	fmdmeta_prop.gridconf.colType="tree,ro";
	fmdmeta_prop.gridconf.colIds="prop,value";
	fmdmeta_prop.gridconf.colAlign="left,left";
	//fmdmeta_prop.gridconf.colVAlign;
	fmdmeta_prop.gridconf.colSorting="na,na";
	//fmdmeta_prop.gridconf.colMinWidth;
	fmdmeta_prop.gridconf.colInitWidth="200,140";
	fmdmeta_prop.gridconf.colColor="#F8F8F8,white";
	//fmdmeta_prop.gridconf.resize;
	fmdmeta_prop.gridconf.visibile="false,false";
	fmdmeta_prop.gridconf.enableTooltips="false,true";
	fmdmeta_prop.gridconf.idx={};
	fmdmeta_prop.gridconf.idx.prop=0;
	fmdmeta_prop.gridconf.idx.value=1;
	fmdmeta_prop.gridconf.tiprowbgcolor = "#e6f8fe";

	fmdmeta_prop.common = {};	//common properties settings for components
	//fmdmeta_prop.common.all = {};	//common properties settings for all components
	fmdmeta_prop.common.layout = {};	//common properties settings for all layout components
	//fmdmeta_prop.common.datacontrol = {};	//common properties settings for all datacontrol components
	//fmdmeta_prop.common.usercontrol = {};	//common properties settings for all usercontrol components
	fmdmeta_prop.layout = {};	//properties settings for layout components
	fmdmeta_prop.control = {};	//properties settings for all control components
	fmdmeta_prop.func = {};	//common functions
	
	//predefined events
	fmdmeta_prop.propDhxGridPredefinedEvents = {
		"onCellChanged" : function(rId,cId,nv) {
			//console.debug("onCellChanged======="+nv);
			//alert((rId.indexOf('i18nname')!=-1)+"=="+rId+"=="+(!fmdc.grid_prop.cells(rId, fmdmeta_prop.gridconf.idx.value).getValue()));
			//var newv = fmdc.grid_prop.cells(rId, fmdmeta_prop.gridconf.idx.value).getValue();
			if (cId==fmdmeta_prop.gridconf.idx.value && nv!='&nbsp;') {
				var $sobj = designer.getSelected();
				if (!$sobj) return;
				//ConditionalSub
				//var types = fmdf_getElemCompTypes($sobj);
				//change value
				fmdc.version.formdata.propconf[$sobj.attr("id")][rId] = nv;
				
				var confs = JSONSelect.match("."+rId, fmdmeta_prop[fmdc.proptemp["compType"]][fmdc.proptemp["type"]]);
				if (nv && confs && confs[0] && confs[0]["conditional-sub"]) {
					fmdpf_showConditionalSub(rId, nv, confs[0]);
				}
				
				//i18nname
				if (!nv && rId.indexOf('i18nname')!=-1) {
					if ('i18nname-zh'==rId) {
						fmdc.grid_prop.cells(rId, cId).setValue(fmd_i18n_untitled);
					} else {
						fmdc.grid_prop.cells(rId, cId).setValue("Untitled");
					}
				}
				fmdc.unsavedchange = true;
				fmdmeta_prop[fmdc.proptemp["compType"]][fmdc.proptemp["type"]].onApply && fmdmeta_prop[fmdc.proptemp["compType"]][fmdc.proptemp["type"]].onApply();
				
				confs && confs[0] && fmdmeta_prop.func.valueChanged($sobj.attr("id"), confs[0]);
			}
		},
		"onEditCell" : function(stage,rId,cInd,nv,ov){//这里定义的方法，在每个组件属性的每个onEditCell事件时都会调用
			/*console.debug("1onEditCell=======");
			console.debug("1     stage======="+stage);
			console.debug("1       rId======="+rId);
			console.debug("1      cInd======="+cInd);
			console.debug("1    nValue======="+nv);
			console.debug("1    oValue======="+ov);
			console.debug("1onEditCell======="+ this.cells(rId,cInd).getValue());*/
			var $sobj = designer.getSelected();
			if (!$sobj) return;
			var ov = fmdc.version.formdata.propconf[$sobj.attr("id")][rId];
			if (stage==0) {
				
			} /*else if ('ch'==this.getCellExcellType(rId,cInd) && stage==1) {
				//处理checkbox类型的属性值被用户修改时
				nv = this.cells(rId,cInd).getValue();
				if (ov && !MyUtilJs.isEqual(ov, nv)) {
					fmdc.version.formdata.propconf[$sobj.attr("id")][rId] = nv;
					//console.debug("onEditCell ch excel changed. fl.unSavedChange changed.");
					fmdc.unsavedchange = true;
				}
			}*/ else if (stage==2 && !MyUtilJs.isEqual(ov, nv) && nv!='&nbsp;') {
				fmdc.version.formdata.propconf[$sobj.attr("id")][rId] = nv;
				//console.debug("onEditCell stage==2 changed. fl.unSavedChange changed.");
				fmdc.unsavedchange = true;
			}
			return true;
		}
	};

	//available validators
	fmdmeta_prop.runtime_validators = [["None",fmd_i18n_vld_none],
					["NotEmpty", fmd_i18n_vld_notempty],
					["LengthLimit", fmd_i18n_vld_lengthlimit],
					["ValidAplhaNumeric", fmd_i18n_vld_alphanumeric],
					["ValidAplhaNumericUnderline", fmd_i18n_vld_alphanumericunderline],
					["ValidDate", fmd_i18n_vld_date + '(yyyy-MM-dd)'],
					["ValidDatetimeMM", fmd_i18n_vld_datetime + '(yyyy-MM-dd hh:mm)'],
					["ValidDatetimeSS", fmd_i18n_vld_datetime + '(yyyy-MM-dd hh:mm:ss)'],
					["ValidTime", fmd_i18n_vld_time + '(hh:mm:ss)'],
					["ValidTimeNoSS", fmd_i18n_vld_time + '(hh:mm)'],
					["ValidInteger", fmd_i18n_vld_integer],
					["ValidAge", fmd_i18n_vld_age],
					["ValidIdCard", fmd_i18n_vld_IdCard],
					["ValidPositiveInteger", fmd_i18n_vld_positiveinteger],
					["ValidNonNegativeinteger", fmd_i18n_vld_NonNegativeinteger],
					["ValidNumeric", fmd_i18n_vld_numeric],
					["ValidCurrency", fmd_i18n_vld_currency],
					["ValidEmail", fmd_i18n_vld_email],
					["ValidCnMobile", fmd_i18n_vld_cnmobile],
					["ValidCnPhone", fmd_i18n_vld_cnphone],
					["ValidIPv4", fmd_i18n_vld_ipv4],
					["RegExp", fmd_i18n_vld_regexp]
	                      ];
	
	fmdmeta_prop.validators = {};

	fmdmeta_prop.validators["NotEmpty"] = 
	{
		"func" : "(v){"+
						"return v!=null && ''!=$.trim(v);"+
					  "}",
		"zh" : "不能为空",
		"en" : "Empty is not allowed"
	};

	fmdmeta_prop.validators["ValidAplhaNumeric"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;var regu = '^[0-9a-zA-Z]+$';var re = new RegExp(regu);if (re.test(v)) {return true;}else{return false;}"+
					  "}",
		"zh" : "只能为字母和数字",
		"en" : "Only english charactors and numbers are allowed"
	};

	fmdmeta_prop.validators["ValidAplhaNumericUnderline"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;var regu = '^[0-9a-zA-Z\_]+$';var re = new RegExp(regu);if (re.test(v)) {return true;}else{return false;}"+
					  "}",
		"zh" : "只能为字母、数字和下划线",
		"en" : "Only english charactors, numbers and underline are allowed"
	};

	fmdmeta_prop.validators["ValidCurrency"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;var regu = '^[0-9]+[\.][0-9]{0,2}$';var re = new RegExp(regu);if (re.test(v)) {return true;}else {return false;}"+
					  "}",
		"zh" : "不是有效金额",
		"en" : "Not valid currency"
	};

	fmdmeta_prop.validators["ValidDate"] = 
	{
		"func" : "(v){"+
			"if (v==null || ''==$.trim(v)) return true;\n" +
		    'var fmt = "yyyy-MM-dd";\n'+
		    'var yIndex = fmt.indexOf("yyyy");\n'+
		    'if (yIndex ==- 1) {\n'+
		        'return false;\n'+
		    '}\n'+
		    'var year = v.substring(yIndex, yIndex + 4);\n'+
		    'var mIndex = fmt.indexOf("MM");\n'+
		    'if (mIndex ==- 1) {\n'+
		        'return false;\n'+
		    '}\n'+
		    'var month = v.substring(mIndex, mIndex + 2);\n'+
		    'var dIndex = fmt.indexOf("dd");\n'+
		    'if (dIndex ==- 1) {\n'+
		        'return false;\n'+
		    '}\n'+
		    'var day = v.substring(dIndex, dIndex + 2);\n'+
		    'if (isNaN(year) || year > "2100" || year < "1900") {\n'+
		        'return false;\n'+
		    '}\n'+
		    'if (isNaN(month) || month > "12" || month < "01") {\n'+
		        'return false;\n'+
		    '}\n'+
		    'var maxday = 31;\n'+
		    'if (month == 4 || month == 6 || month == 9 || month == 11) {\n'+
		    	'maxday = 30;\n'+
		    '}\n'+
		    'if (month == 2) {\n'+
		        'if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {\n'+
		        	'maxday = 29;\n'+
		        '}\n'+
		        'else {\n'+
		        	'maxday = 28;\n'+
		        '}\n'+
		    '}\n'+
		    'if (day > maxday || day < "01") {\n'+
		        'return false;\n'+
		    '}\n'+
		    'return true;\n'+
			"}",
		"zh" : "不是有效日期 (yyyy-MM-dd)",
		"en" : "Not valid date (yyyy-MM-dd)"
	};

	fmdmeta_prop.validators["ValidDatetimeMM"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;\n"+
						"var regu=/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d$/;"+
						"return regu.test(v);\n"+
					  "}",
		"zh" : "不是有效日期时间格式 (yyyy-MM-dd hh:mm)",
		"en" : "Not validate date and time (yyyy-MM-dd hh:mm)"
	};

	fmdmeta_prop.validators["ValidDatetimeSS"] = 
	{
		"func" : "(v){"+
		                "if (v==null || ''==$.trim(v)) return true;\n"+
						"var regu=/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$/;"+
						"return regu.test(v);\n"+
					  "}",
		"zh" : "不是有效日期时间格式 (yyyy-MM-dd hh:mm:ss)",
		"en" : "Not validate date and time (yyyy-MM-dd hh:mm:ss)"
	};

	fmdmeta_prop.validators["ValidEmail"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;\n"+
						"var emailReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[-|_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;\n"+
					    "return emailReg.test(v);"+
					  "}",
		"zh" : "不是有效邮箱地址",
		"en" : "Not valid email address"
	};

	fmdmeta_prop.validators["ValidAge"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;\n"+
						"var regu = /^(?:[0-9][0-9]?|1[01][0-9]|120)$/;return regu.test(v);"+
					  "}",
		"zh" : "不是有效年龄",
		"en" : "Not valid age"
	};

	fmdmeta_prop.validators["ValidIdCard"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;\n"+
						"var regu = /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/;return regu.test(v);"+
					  "}",
		"zh" : "不是有效身份证号",
		"en" : "Not valid IdCard"
	};

	fmdmeta_prop.validators["ValidInteger"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;\n"+
						"var regu = /^[-]{0,1}[0-9]{1,}$/;return regu.test(v);"+
					  "}",
		"zh" : "不是有效整数",
		"en" : "Not valid integer"
	};

	fmdmeta_prop.validators["ValidPositiveInteger"] = 
	{
		"func" : "(v){"+
					   "if (v==null || ''==$.trim(v)) return true;\n"+
						"var regu = /^[1-9]*[1-9][0-9]*$/;return regu.test(v);"+
					  "}",
		"zh" : "不是有效正整数",
		"en" : "Not valid positive integer"
	};

	fmdmeta_prop.validators["ValidNonNegativeinteger"] = 
	{
		"func" : "(v){"+
					   "if (v==null || ''==$.trim(v)) return true;\n"+
						"var regu = /(^[0-9]+\d*$)|(^0$)/;return regu.test(v);"+
					  "}",
		"zh" : "不是有效非负整数",
		"en" : "Not valid Non Negative integer"
	};

	fmdmeta_prop.validators["ValidIPv4"] = 
	{
		"func" : "(v){"+
		        "if (v==null || ''==$.trim(v)) return true;\n"+
			    "var re = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;\n"+
			    /*"if (re.test(v)) {\nalert(RegExp.$1);"+
			        "if ( RegExp.$1 < 256 && RegExp.$1>=0 && RegExp.$2 < 256 && RegExp.$2>=0 && RegExp.$3 < 256 && RegExp.$3>=0 && RegExp.$4 < 256 && RegExp.$4>=0) {\n"+
			            "alert(2);return true;\n"+
			        "}\n"+
			    "}\n"+*/
			    "return re.test(v);\n"+
					  "}",
		"zh" : "不是有效IP(v4)地址",
		"en" : "Not valid IP(v4) address"
	};

	fmdmeta_prop.validators["ValidNumeric"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;return !isNaN(v);"+
					  "}",
		"zh" : "不是有效数字",
		"en" : "Not a valid number"
	};

	fmdmeta_prop.validators["ValidTime"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;var regu=/([01]\d|2[0-3]):([0-5][0-9]):([0-5][0-9])/;"+
						"return regu.test(v);"+
					  "}",
		"zh" : "不是有效时间格式(hh:mm:ss)",
		"en" : "Not a valid time format(hh:mm:ss)"
	};

	fmdmeta_prop.validators["ValidTimeNoSS"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;var regu=/([01]\d|2[0-3]):([0-5][0-9])/;"+
						"return regu.test(v);"+
					  "}",
		"zh" : "不是有效时间格式(hh:mm)",
		"en" : "Not a valid time format(hh:mm)"
	};

	fmdmeta_prop.validators["ValidCnMobile"] = 
	{
		"func" : "(v){"+
						"if (v==null || ''==$.trim(v)) return true;var regu = /^[1][3,5,7,8][0-9]{9}$/;"+
					    "return regu.test(v);"+
					  "}",
		"zh" : "不是有效国内手机号",
		"en" : "Not a valid chinese mobile number"
	};

	fmdmeta_prop.validators["ValidCnPhone"] = 
	{
		"func" : "(v){"+
		                "if (v==null || ''==$.trim(v)) return true;\n"+
						"var phoneRegWithArea = /^[0][1-9]{2,3}-[0-9]{5,10}$/;"+
					    "var phoneRegNoArea = /^[1-9]{1}[0-9]{5,8}$/;"+
					    "if ( v.length > 9 ) {"+
					    "    if ( phoneRegWithArea.test(v) ) {"+
					    "        return true;"+
					    "    } else {"+
					    "        return false;"+
					    "    }"+
					    "} else {"+
					    "    if ( phoneRegNoArea.test( v ) ) {"+
					    "        return true;"+
					    "    } else {"+
					    "        return false;"+
					    "    }"+
					    "}"+
					"}",
		"zh" : "不是有效国内电话号码",
		"en" : "Not a valid chinese phone number"
	};

	fmdmeta_prop.validators["LengthLimit"] = 
	{
		"func" : "(v, c){"+
						"if (v==null || ''==$.trim(v)) return true;return v.toString().length<=Number(c)"+
					  "}",
		"condition" : true,
		"conditionValidator" : "ValidPositiveInteger",
		"zh" : "输入的数据过长",
		"en" : "Value is too long"
	};

	fmdmeta_prop.validators["RegExp"] = 
	{
		"func" : "(v, c){"+
						"if (v==null || ''==$.trim(v)) return true;return new RegExp(c).test(v);"+
					  "}",
		"condition" : true,
		"zh" : "不是有效格式数据",
		"en" : "Not a valid format data"
	};
	
	/**
	 * list of available controls
	 */
	//==================== common ====================

	/**
	 * common for all components
	 */
	fmdmeta_prop.common.all = {
			"properties" : {
				"id" : {
			    	"name" : "id",
			    	"img" : "id.png",
			    	"cellType" : "ro",
			    	"value" : {"fromattr" : "id"}/*,
			    	"displayOnly" : true*/
			    },
			    "i18nname" : {
			    	"name" : fmd_i18n_prop_i18nname,
			    	"cellType" : "ro",
			    	"img" : "locale.png",
			    	"displayOnly" : true,
			    	"sub" : {
			    		"i18nname-zh" : {
			    			"name" : fmd_i18n_prop_i18nname_zh,
			    			"cellType" : "ed",
					    	"validator" : "NotEmpty",
					    	"img" : "zh.png",
					    	"value" : {"default": fmd_i18n_untitled}
			    		},
			    		"i18nname-en" : {
			    			"name" : fmd_i18n_prop_i18nname_en,
			    			"cellType" : "ed",
					    	//"validator" : "NotEmpty",
					    	"img" : "en.png",
					    	"value" : {"default": "Untitled"}
			    		}
			    	}
			    },
			    "display" : {
			    	"name" : fmd_i18n_prop_display,
			    	"img" : "display.png",
			    	"cellType" : {"type":"coro",
							    	"options":[["displayblock",fmd_i18n_prop_displayblock],
										         //["displayblockinline",fmd_i18n_prop_displayblockinline],
										         ["displaynone",fmd_i18n_prop_displaynone],
										         ["visibilityhidden",fmd_i18n_prop_visibilityhidden]
											  	]
			    				},
					"value" : {"default" : "displayblock"}
			    },
			    "classNames" : {
			    	"name" : fmd_i18n_prop_classname,
			    	"img" : "css.png",
			    	"validator" : "ValidClassNames",
			    	"tooltip" : fmd_i18n_tooltip_classname,
			    	"cellType" : "ed"
			    },
			    "style" : {
			    	"name" : fmd_i18n_prop_style,
			    	"img" : "css.png",
			    	"tooltip" : fmd_i18n_tooltip_style,
			    	"cellType" : "ace_text"
			    }
			},
			"events" : {
				"click" : {"name" : fmd_i18n_ev_onclick,
					"arguments" : {
						"e" : fmd_i18n_ev_eventobj
					}
				},
				"mouseenter" : {"name" : fmd_i18n_ev_onmouseover,
					"arguments" : {
						"e" : fmd_i18n_ev_eventobj
					}
				},
				"mouseleave" : {"name" : fmd_i18n_ev_onmouseout,
					"arguments" : {
						"e" : fmd_i18n_ev_eventobj
					}
				}
			}
		};

	/**
	 * common for all datacontrol components
	 */
	fmdmeta_prop.common.datacontrol = {
			"properties" : {
				/*"label" : {
			    	"name" : fmd_i18n_prop_label,
			    	"cellType" : "ro",
			    	"validator" : "Required"
			    },*/
			    "hideLabel" : {
			    	"name" : fmd_i18n_prop_hidelabel,
			    	"cellType" : "ch",
			    	"value" : {"default":"0"}
			    },
			    /*"labelPosition" : {
			    	"name" : fmd_i18n_prop_labelposition,
			    	"cellType" : {"type":"coro", 
			    				"options":[["left",fmd_i18n_prop_left],
	                                     ["right",fmd_i18n_prop_right],
	                                     ["top",fmd_i18n_prop_top],
	                                     ["bottom",fmd_i18n_prop_bottom]
			    				]
			    	},
			    	"value" : {"default":"top"}
			    },
			    "required" : {
			    	"name" : fmd_i18n_prop_required,
			    	"cellType" : "ch",
			    	"value" : {"default":"0"}
			    },*/
			    "disabled" : {
			    	"name" : fmd_i18n_prop_disabled,
			    	"cellType" : "ch",
			    	"value" : {"default":"0"}
			    },
			    /*"keepOnDisabled" : {
			    	"name" : fmd_i18n_prop_keepondisabled,
			    	"cellType" : "ch",
			    	"value" : {"default":"0"}
			    }*/
			    /*"valueValidation" : {
			    	"name" : fmd_i18n_prop_valuevalidation,
				    "cellType" : {
						"type" : "coro",
						"options":fmdmeta_prop.runtime_validators
				    },
					"conditional-sub" : {
						"RegExp" : {
							"valueValidation-RegExp" : {
								"name" : fmd_i18n_prop_regexp,
								"cellType" : "ed",
								"validator" : "NotEmpty"
							}
					    }
					},
				    "value" : {"default":""}
			    },*/
			    /*"tabIndex" : {
			    	"name" : fmd_i18n_prop_tabindex,
			    	"cellType" : "ed",
			    	"validator" : "ValidInteger"
			    },*/
			    "hidefor" : {
			    	"name" : fmd_i18n_prop_hidefor,
			    	"cellType" : {
			    		"type" : "btnex",
			    		"config" : {
							"displayValue" : "displayValue",
							//包一层方法是因为此处被调用方法还未声明
		    				"onclick" : function(rId, cId){fmdmeta_prop.func.selectHideFor(rId, cId);},
		    				"imgName1" : "delete.png",
		    				"onclick1" : function(rId, cId){fmdmeta_prop.func.clearHideFor(rId, cId);}
		    			}
			    	},
			    	"value" : {"default":{}}
			    },
			    "i18ntip" : {
			    	"name" : fmd_i18n_prop_i18ntip,
			    	"cellType" : "ro",
			    	"img" : "locale.png",
			    	"displayOnly" : true,
			    	"tooltip" : fmd_i18n_tooltip_i18ntip,
			    	"sub" : {
			    		"i18ntip-zh" : {
			    			"name" : fmd_i18n_prop_i18nname_zh,
			    			"cellType" : "ed",
					    	//"validator" : "NotEmpty",
					    	"img" : "zh.png"
			    		},
			    		"i18ntip-en" : {
			    			"name" : fmd_i18n_prop_i18nname_en,
			    			"cellType" : "ed",
					    	//"validator" : "NotEmpty",
					    	"img" : "en.png"
			    		}
			    	}
			    }
			},
			"events" : {
				"change" : {"name" : fmd_i18n_ev_onchange,
					"arguments" : {
						"e" : fmd_i18n_ev_eventobj
					}
				},
				"focus" : {"name" : fmd_i18n_ev_onfocus,
					"arguments" : {
						"e" : fmd_i18n_ev_eventobj
					}
				},
				"blur" : {"name" : fmd_i18n_ev_onblur,
					"arguments" : {
						"e" : fmd_i18n_ev_eventobj
					}
				}//,
//				"disabled" : {},
//				"enabled" : {}
			}
		};
	
	/**
	 * common properties settings for all usercontrol components
	 */
	fmdmeta_prop.common.usercontrol = {};

	//==================== layout ====================

	//properties settings for tab
	fmdmeta_prop.layout.tab = {
			"includes-properties" : {
				"common" : fmdmeta_prop.common.all.properties
			},
			"properties" : {
				"i18ntype" : {
			    	"name" : fmd_i18n_prop_selectiontype,
			    	"img" : "selection.png",
			    	"cellType" : "ro",
			    	"value" : {"default":fmd_i18n_l_fmcontainer_tab},
			    	"displayOnly" : true,
			    	"afterProperty" : "id"
			    }
			},
			"abandon-properties" : ["tiprow_specific"],//format is array
			"includes-events" : {
				"common" : fmdmeta_prop.common.all.events
			},
			"events" : {
				"onactive" : {"name" : fmd_i18n_ev_onactive,
					"arguments" : {
						"e" : fmd_i18n_ev_eventobj,
						"obj" : fmd_i18n_ev_eventthis
					}
				}
			},
			"onApply" : function() {
				var vals = fmdc.version.formdata.propconf[designer.getSelected().attr("id")];
				designer.fmcontainer_tab_title(vals["i18nname-"+fmd.lang]);
			}
		};

	//properties settings for block
	fmdmeta_prop.layout.block = {
			"includes-properties" : {
				"common" : fmdmeta_prop.common.all.properties
			},
			"properties" : {
				"i18ntype" : {
			    	"name" : fmd_i18n_prop_selectiontype,
			    	"img" : "selection.png",
			    	"cellType" : "ro",
			    	"value" : {"default":fmd_i18n_l_fmcontainer_block},
			    	"displayOnly" : true,
			    	"afterProperty" : "id"
			    },
			    "pattern" : {
			    	"name" : fmd_i18n_prop_container_pattern,
			    	"img" : "pattern.png",
			    	"cellType" : "ro",
			    	"value" : {"fromattr":"fmdpattern"},
			    	"afterProperty" : "i18ntype"
			    },
				"margintop" : {
			    	"name" : fmd_i18n_prop_container_margintop,
			    	"cellType" : "ed",
			    	"value" : {"default" : "0.7"},
			    	"validator" : "ValidNumeric"
			    },
			    "noheader" : {
			    	"name" : fmd_i18n_prop_container_noheader,
			    	"cellType" : "ch",
			    	"value" : {"default":"0"}
			    },
			    "fold" : {
			    	"name" : fmd_i18n_prop_container_fold,
			    	"cellType" : "ch",
			    	"value" : {"default":"0"}
			    },
			    "hidefor" : {
			    	"name" : fmd_i18n_prop_hidefor,
			    	"cellType" : {
			    		"type" : "btnex",
			    		"config" : {
							"displayValue" : "displayValue",
							//包一层方法是因为此处被调用方法还未声明
		    				"onclick" : function(rId, cId){fmdmeta_prop.func.selectHideFor(rId, cId);},
		    				"imgName1" : "delete.png",
		    				"onclick1" : function(rId, cId){fmdmeta_prop.func.clearHideFor(rId, cId);}
		    			}
			    	}
			    }
			},
			"includes-events" : {
				"common" : fmdmeta_prop.common.all.events
			},
			"events" : {
				"onCollapse" : {"name" : fmd_i18n_ev_oncollapse,
					"arguments" : {
						"e" : fmd_i18n_ev_eventobj,
						"obj" : fmd_i18n_ev_eventthis
					}
				},
				"onExpand" : {"name" : fmd_i18n_ev_onexpand,
					"arguments" : {
						"e" : fmd_i18n_ev_eventobj,
						"obj" : fmd_i18n_ev_eventthis
					}
				}
			},
			"onApply" : function() {
				var vals = fmdc.version.formdata.propconf[designer.getSelected().attr("id")];
				designer.fmcontainer_block_title(vals["i18nname-"+fmd.lang]);
				fmdc.selection.selectedobj.css('margin-top', vals["margintop"]?vals["margintop"]+'em':'0.7em');
				designer.fmcontainer_block_headerdisplay(vals["noheader"]);
			}
		};
	
	//properties settings for cell
	fmdmeta_prop.layout.cell = {
			"includes-properties" : {
				"common" : fmdmeta_prop.common.all.properties
			},
			"properties" : {
				"i18ntype" : {
			    	"name" : fmd_i18n_prop_selectiontype,
			    	"img" : "selection.png",
			    	"cellType" : "ro",
			    	"value" : {"default":fmd_i18n_l_fmcontainer_cell},
			    	"displayOnly" : true,
			    	"afterProperty" : "id"
			    }/*,
			    "rowspan" : {
			    	"name" : fmd_i18n_t_rowspan,
			    	"img" : "rowspan.png",
			    	"cellType" : "ro",
			    	"value" : {"fromattr":"rowspan", "default":"1"}
			    },
			    "colspan" : {
			    	"name" : fmd_i18n_t_colspan,
			    	"img" : "colspan.png",
			    	"cellType" : "ro",
			    	"value" : {"fromattr":"colspan", "default":"1"}
			    }*/
			},
			"abandon-properties" : ["i18nname","classNames","style", "display"],	//format is array
			/*"includes-events" : {
				"common" : fmdmeta_prop.common.all.events
			},*/
			"onApply" : function() {}
		};

	//on value changed of current component
	fmdmeta_prop.func.valueChanged = function(elid, propconf) {
		if (propconf.clearAfterChange) {
			var scope = propconf.clearAfterChange.scope || "current";
			if (scope=="current") {//current component
				if ($.isArray(propconf.clearAfterChange.properties)) {
					for (var p in propconf.clearAfterChange.properties) {
						fmdc.grid_prop.cells(propconf.clearAfterChange.properties[p], fmdmeta_prop.gridconf.idx.value).setValue(null);
					}
				}
			} else if (scope=="all") {
				if ($.isArray(propconf.clearAfterChange.properties)) {
					for (var t in propconf.clearAfterChange.properties) {
						if (t==fmdc.proptemp["type"]) {//current component
							for (var p in propconf.clearAfterChange.properties[t].list) {
								fmdc.grid_prop.cells(propconf.clearAfterChange.properties[t].list[p], fmdmeta_prop.gridconf.idx.value).setValue(null);
							}
						} else {//other component
							for (var eid in fmdc.version.formdata.propconf) {
								if (fmdc.version.formdata.propconf[eid].i18ntype==t) {
									for (var p in propconf.clearAfterChange.properties[t].list) {
										delete fmdc.version.formdata.propconf[eid][propconf.clearAfterChange.properties[t].list[p]];
									}
								}
							}
						}
					}
				}
			}
		}
	};
	
	//选择字典
	fmdmeta_prop.func.selectDict = function(rId, cId, propgrid) {
		var w1 = fm_createCenterWindow('wid_selectDict', fmd_i18n_prop_selectDict, 600, 600);
		
		var lo1 = w1.attachLayout("2E");
		lo1.cells('a').hideHeader();
		lo1.cells('b').hideHeader();
		lo1.cells('b').setHeight(50);
		var stb1 = lo1.cells('a').attachStatusBar();
		stb1.setText("<div id='id_paging_selectDict1'></div>");
		
		var str2 = [{ type:"block" , name:"form_block_1", offsetLeft:(dhx_skin=="dhx_web"?"230":"240"), offsetTop:"0", list:[
			   		{ type:"button" , name:"fb_ok", value:fmd_i18n_b_ok, inputTop:0}]}];
		var fm2 = lo1.cells('b').attachForm(str2);
		var dictq = {};
		dictq.rest_query = fmd.fmdCtx + "/rest/metadata/queryDict";
		
		//grid
		var selgrid = lo1.cells('a').attachGrid();
		selgrid.setHeader([fmd_i18n_l_no,
		                  fmd_i18n_prop_dict_type,
		                  fmd_i18n_prop_dict_typedesc],
		                    null,
		                    ["text-align:center;",
		                     "text-align:center;",
		                     "text-align:center;"]);
		selgrid.attachHeader("#rspan,<input id='sr_type' type='text' style='width:90%'/>,<input id='sr_typedesc' type='text' style='width:90%'/>");
		selgrid.setInitWidths("60,180,300");
		selgrid.setColumnIds("NO,TYPE,TYPEDESC");
		selgrid.setColTypes("ro,ro,ro");
		selgrid.setColSorting("int,str,str");
		selgrid.setColumnsVisibility("false,false,false");
		selgrid.setColAlign("center,left,left");
		selgrid.setEditable(false);
		selgrid.setLang(fmd.lang);
		selgrid.init();
		selgrid._grid_ordercolumns = [{"TYPE":"ASC"}];
		
		//paging
		selgrid.setPagingWTMode(true,true,true,[20,50,100]);
		selgrid.enablePaging(true,20,5,'id_paging_selectDict1');
		selgrid.setPagingSkin("toolbar", dhx_skin);
		
		selgrid.attachEvent("onRowDblClicked", function(rid) {
			var type = selgrid.cells(rid, 1).getValue();
			var typeDesc = selgrid.cells(rid, 2).getValue();
			var newval = {"type":type, "typeDesc":typeDesc, "displayValue":type+"["+typeDesc+"]"};
			if (propgrid) {
				propgrid.cells(rId, cId).setValue(newval, true);	//第二个参数必须为true，触发事件
			} else {
				fmdc.grid_prop.cells(rId, cId).setValue(newval, true);	//第二个参数必须为true，触发事件
			}
			w1.close();
		});
		
		selgrid.attachEvent("onPageChanged", function(ind,fInd,lInd){
			dict_toPage(fInd+1, lInd);
		});
		
		//header click event
		selgrid.attachEvent("onHeaderClick", grid_onHeaderClick);
		
		//bind searcher event
		//disable onclick order by function for this header
		var trsr_type = $("#sr_type").parents('tr:first');
		trsr_type.find('td').bind('click',utp_stopEvent);
		trsr_type.find('td').bind('mouseover',utp_stopEvent);
		$("#sr_type").bind('keypress', dict_enterQuery);
		$("#sr_typedesc").bind('keypress', dict_enterQuery);
		
		fm2.attachEvent("onButtonClick", function(btid) {
			if (btid=='fb_ok') {
				var rid = selgrid.getSelectedRowId();
				if (!rid) {
					msg(fmd_i18n_msg_sel);
					return;
				}
				var type = selgrid.cells(rid, 1).getValue();
				var typeDesc = selgrid.cells(rid, 2).getValue();
				var newval = {"type":type, "typeDesc":typeDesc, "displayValue":type+"["+typeDesc+"]"};
				if (propgrid) {
					propgrid.cells(rId, cId).setValue(newval, true);	//第二个参数必须为true，触发事件
				} else {
					fmdc.grid_prop.cells(rId, cId).setValue(newval, true);	//第二个参数必须为true，触发事件
				}
				w1.close();
			}
		});
		
		dict_toPage(1, 20);
		
		//stop event propagation
		function utp_stopEvent(e){
			if (e && e.stopPropagation!=undefined) {
				e.stopPropagation();
			} else if (window.event){
				window.event.cancelBubble = true;
			}
			return false;
		}
		
		//query version
		function dict_toPage(fromRow, toRow){
			lo1.cells('b').progressOn();
			var p = {"args":{"target":"BPM","category":"ENUMERATION"}, "fromRow":fromRow, "toRow":toRow, "timezoneOffset":new Date().getTimezoneOffset(),
					"ordercolumns":JSON.stringify(selgrid._grid_ordercolumns)};
			if (dictq.vquery_type) {
				p.args.type = dictq.vquery_type;
			}
			if (dictq.vquery_typedesc) {
				p.args.typedesc = dictq.vquery_typedesc;
			}
			p.args = JSON.stringify(p.args);
			var ret = doPostSyncJson(dictq.rest_query, p);
			if (!ret) {
				lo1.cells('b').progressOff();
				msgErr(fmd_i18n_msg_readfail);
				return;
			}
			selgrid.clearAllInPaging();
			selgrid.parse(ret, "json");
			lo1.cells('b').progressOff();
		}

		//call query version
		function dict_enterQuery(e) {
			if (e.keyCode==13) {
				dictq.vquery_type = $.trim($("#sr_type").val());
				dictq.vquery_typedesc = $.trim($("#sr_typedesc").val());
				selgrid.currentPage = 1;
				dict_toPage(1, 20);
			}
		}
	};
	
	//选择字典
	fmdmeta_prop.func.selectService = function(rId, cId, propgrid) {
		var w1 = fm_createCenterWindow('wid_selectService', fmd_i18n_prop_selectService, 800, 600);
		
		var lo1 = w1.attachLayout("3U");
		lo1.cells('a').hideHeader();
		lo1.cells('b').hideHeader();
		lo1.cells('c').hideHeader();
		lo1.cells('a').setWidth(300);
		lo1.cells('c').setHeight(50);
		var stb1 = lo1.cells('a').attachStatusBar();
		stb1.setText("<div id='id_paging_selectService1'></div>");
		
		var str2 = [{ type:"block" , name:"form_block_1", offsetLeft:(dhx_skin=="dhx_web"?"330":"340"), offsetTop:"0", list:[
			   		{ type:"button" , name:"fb_ok", value:fmd_i18n_b_ok, inputTop:0}]}];
		var fm2 = lo1.cells('c').attachForm(str2);
		var svcq = {};
		svcq.rest_get = fmd.fmdCtx + "/rest/service/";
		svcq.rest_query = fmd.fmdCtx + "/rest/service/query";
		
		//grid
		var ragrid = lo1.cells('a').attachGrid();
		ragrid.setHeader([fmd_i18n_l_no,
		                  'ID',
		                  fmd_i18n_prop_svc_desc,
		                  fmd_i18n_prop_svc_uri],
		                    null,
		                    ["text-align:center;",
		                     "text-align:center;",
		                     "text-align:center;",
		                     "text-align:center;"]);
		ragrid.attachHeader("#rspan,#rspan,<input id='sr_desc' type='text' style='width:90%'/>,<input id='sr_uri' type='text' style='width:90%'/>");
		ragrid.setInitWidths("60,100,230,300");
		ragrid.setColumnIds("NO,ID,DESC,URI");
		ragrid.setColTypes("ro,ro,ro,ro");
		ragrid.setColSorting("int,str,str,str");
		ragrid.setColumnsVisibility("false,true,false,true");
		ragrid.setColAlign("center,left,left,left");
		ragrid.setEditable(false);
		ragrid.setLang(fmd.lang);
		ragrid.init();
		ragrid._grid_ordercolumns = [{"CREATE_TIME":"DESC"}];
		
		//paging
		ragrid.setPagingWTMode(true,true,true,[10,50,100]);
		ragrid.enablePaging(true,10,5,'id_paging_selectService1');
		ragrid.setPagingSkin("toolbar", dhx_skin);
		
		ragrid.attachEvent("onPageChanged", function(ind,fInd,lInd){
			svc_toPage(fInd+1, lInd);
		});
		
		//header click event
		ragrid.attachEvent("onHeaderClick", grid_onHeaderClick);
		
		//onselect row
		ragrid.attachEvent("onSelectStateChanged", function(rid) {
			if (!rid) return;
			var svcid = ragrid.cells(rid, 1).getValue();
			initSvcDetail(svcid);
		});
		
		//bind searcher event
		//disable onclick order by function for this header
		var trsr_type = $("#sr_desc").parents('tr:first');
		trsr_type.find('td').bind('click',utp_stopEvent);
		trsr_type.find('td').bind('mouseover',utp_stopEvent);
		$("#sr_desc").bind('keypress', dict_enterQuery);
		$("#sr_uri").bind('keypress', dict_enterQuery);
		
		//stop event propagation
		function utp_stopEvent(e){
			if (e && e.stopPropagation!=undefined) {
				e.stopPropagation();
			} else if (window.event){
				window.event.cancelBubble = true;
			}
			return false;
		}
		
		fm2.attachEvent("onButtonClick", function(btid) {
			if (btid=='fb_ok') {
				var rid = ragrid.getSelectedRowId();
				if (!rid) {
					msg(fmd_i18n_msg_sel);
					return;
				}
				var id = ragrid.cells(rid, 1).getValue();
				var desc = ragrid.cells(rid, 2).getValue();
				var newval = {"realValue":id, "displayValue":desc};
				
				//get vars
				var idxVARNAME = svcq.vargrid.getColIndexById("VARNAME"), 
				idxVARTYPE = svcq.vargrid.getColIndexById("VARTYPE"), 
				idxVARDESC = svcq.vargrid.getColIndexById("VARDESC"),
				idxDEFAULT = svcq.vargrid.getColIndexById("DEFAULT");
				var rn = svcq.vargrid.getRowsNum();
				if (rn>0) {
					intfvars = [];
					for (var i=0; i<rn; i++) {
						var varname = $.trim(svcq.vargrid.cellByIndex(i, idxVARNAME).getValue());
						var vartype = svcq.vargrid.cellByIndex(i, idxVARTYPE).getValue();
						var vardesc = $.trim(svcq.vargrid.cellByIndex(i, idxVARDESC).getValue());
						var vardv = $.trim(svcq.vargrid.cellByIndex(i, idxDEFAULT).getValue());
						var rd = {"varname":varname, "vartype":vartype, "vardesc":vardesc, "default":vardv};
						if (vardv!=undefined && vardv!="") {
							if (vartype=="datetime" && !dhtmlxValidation.isValidDatetimeSS(vardv)) {
								msg(fmd_i18n_elsvc_input+"["+varname+"] : " + fmd_i18n_msg_wrongformatdefaultvalue);
								return;
							} else if (vartype=="int" && !dhtmlxValidation.isValidInteger(vardv)) {
								msg(fmd_i18n_elsvc_input+"["+varname+"] : " + fmd_i18n_msg_wrongformatdefaultvalue);
								return;
							} else if (vartype=="number" && !dhtmlxValidation.isValidNumeric(vardv)) {
								msg(fmd_i18n_elsvc_input+"["+varname+"] : " + fmd_i18n_msg_wrongformatdefaultvalue);
								return;
							} else if (vartype=="json" && !dhtmlxValidation.isValidJsonstr(vardv)) {
								msg(fmd_i18n_elsvc_input+"["+varname+"] : " + fmd_i18n_msg_wrongformatdefaultvalue);
								return;
							}
						}
						intfvars.push(rd);
					}
					newval.intfvars = intfvars;
				}
				
				if (propgrid) {
					propgrid.cells(rId, cId).setValue(newval, true);	//第二个参数必须为true，触发事件
				} else {
					fmdc.grid_prop.cells(rId, cId).setValue(newval, true);	//第二个参数必须为true，触发事件
				}
				w1.close();
			}
		});
		
		svc_toPage(1, 10);
		
		//query version
		function svc_toPage(fromRow, toRow){
			lo1.progressOn();
			var p = {"args":{"target":"BPM","category":"ENUMERATION"}, "fromRow":fromRow, "toRow":toRow, "timezoneOffset":new Date().getTimezoneOffset(),
					"ordercolumns":JSON.stringify(ragrid._grid_ordercolumns)};
			
			var p = {"queryParams":{}, "fromRow":fromRow, "toRow":toRow, "timezoneOffset":new Date().getTimezoneOffset(),
					"ordercolumns":JSON.stringify(ragrid._grid_ordercolumns)};
			if (svcq.vquery_desc) {
				p.queryParams.svcDesc = svcq.vquery_desc;
			}
			if (svcq.vquery_uri) {
				p.queryParams.svcConfig = {"uri":svcq.vquery_uri};
			}
			p.queryParams = JSON.stringify(p.queryParams);
			var ret = doPostSyncJson(svcq.rest_query, p);
			if (!ret) {
				lo1.progressOff();
				msgErr(fmd_i18n_msg_readfail);
				return;
			}
			ragrid.clearAllInPaging();
			ragrid.parse(ret, "json");
			lo1.progressOff();
		}

		//call query version
		function dict_enterQuery(e) {
			if (e.keyCode==13) {
				svcq.vquery_desc = $.trim($("#sr_desc").val());
				svcq.vquery_uri = $.trim($("#sr_uri").val());
				ragrid.currentPage = 1;
				svc_toPage(1, 10);
			}
		}
		
		function initSvcDetail(svcid) {
			lo1.progressOn();
			
			var lod = lo1.cells('b').attachLayout('2E');
			lod.cells('a').setText(fmd_i18n_elsvc_basic);
			lod.cells('a').setHeight(120);
			lod.cells('b').setText(fmd_i18n_elsvc_input);
			
			//basic form
			var str1 = [
				   		{ type:"input" , name:"uri", label:fmd_i18n_elsvc_uri, labelWidth:100, inputWidth:450, readonly:true, offsetLeft:"10", offsetTop:"10", position:"label-top"  }
				   	];
			svcq.fm = lod.cells('a').attachForm(str1);
			
			doGetAsyncJson(svcq.rest_get + svcid,
				function(svc) {
					if (!svc) {
						lo1.progressOff();
						msgErr(fmd_i18n_msg_readfail);
						return;
					}
					
					if (svc.svcConfig && svc.svcConfig.uri) {
						svcq.fm.setItemValue("uri", svc.svcConfig.uri);
					}
					
					svcq.vargrid && svcq.vargrid.destructor && svcq.vargrid.destructor();
					svcq.vargrid=null;
					svcq.vargrid = lod.cells('b').attachGrid();
					svcq.vargrid.setIconsPath(fmd.imagepath);
					svcq.vargrid.setHeader([fmd_i18n_elsvc_hd_name,
					                        fmd_i18n_elsvc_hd_type,
					                        fmd_i18n_elsvc_hd_desc,
					                        fmd_i18n_elsvc_hd_default],
					                    null,
					                    ["text-align:center;",
					                     "text-align:center;",
					                     "text-align:center;",
					                     "text-align:center;"]);
					svcq.vargrid.setInitWidths("100,100,150,120");
					svcq.vargrid.setColumnIds("VARNAME,VARTYPE,VARDESC,DEFAULT");
					svcq.vargrid.setColTypes("ro,pairro,ro,ed");
					svcq.vargrid.setColSorting("na,na,na,na");
					svcq.vargrid.setColumnsVisibility("false,false,false,false");
					svcq.vargrid.setColAlign("left,left,left,right");
					svcq.vargrid.setEditable(true);
					svcq.vargrid.enableEditEvents(true,true);
					svcq.vargrid.enableValidation(true,true);
					svcq.vargrid.setLang(fmd.lang);
					svcq.vargrid.init();
					
					//load vars
					var p = "input";
					if (svc.svcConfig && svc.svcConfig.intfvars && svc.svcConfig.intfvars[p] && svc.svcConfig.intfvars[p].length) {
						for (var i=0; i<svc.svcConfig.intfvars[p].length; i++) {
							var rd = [svc.svcConfig.intfvars[p][i].varname, 
			                          svc.svcConfig.intfvars[p][i].vartype +pairro_spliter+ fmd_i18n_enusvc_vartypes[svc.svcConfig.intfvars[p][i].vartype], 
			                          svc.svcConfig.intfvars[p][i].vardesc];
							rd.push(svc.svcConfig.intfvars[p][i]["default"]);
							svcq.vargrid.addRow(i+1, rd);
						}
					}
					
					lo1.progressOff();
				},
				function(){
					lo1.progressOff();
					msgErr(fmd_i18n_msg_readfail);
				});
		}
	};
	
	fmdmeta_prop.func.selectHideFor = function(rId, cId) {
		if (fmd.roleselrest) {
			fmdmeta_prop.func.selectHideForRest(rId, cId);
		} else if (fmd.roleselurl) {
			fmdmeta_prop.func.selectHideForUrl(rId, cId);
		}
	};
	
	fmdmeta_prop.func.selectHideForRest = function(rId, cId) {
		var w1 = fm_createCenterWindow('wid_selectRoleForHideFor',fmd_i18n_prop_hf_role, 800, 600);

		var rol = {};
		rol.rest_query = (fmd.bpmpCtx=='/' ? '' : fmd.bpmpCtx) + fmd.roleselrest;
		
		var lo1 = w1.attachLayout("2E");
		lo1.cells('a').hideHeader();
		lo1.cells('b').hideHeader();
		lo1.cells('b').setHeight(50);
		rol.stb = lo1.cells('a').attachStatusBar();
		rol.stb.setText("<div id='id_paging_selectHideForRole'></div>");
				
		var str1 = [{ type:"block" , name:"form_block_1", offsetLeft:(dhx_skin=="dhx_web"?"333":"343"), offsetTop:"0", 
				list:[{ type:"button" , name:"fb_ok", value:fmd_i18n_b_ok, inputTop:10}]}];
		var fm2 = lo1.cells('b').attachForm(str1);
		
		//grid
		rol.grid = lo1.cells('a').attachGrid();
		rol.grid.setHeader([fmd_i18n_l_no,
		                    "ROLE_ID",
		                    fmd_i18n_prop_hf_name,
		                    fmd_i18n_prop_hf_desc,
		                    fmd_i18n_prop_hf_cr,
		                    fmd_i18n_prop_hf_ct],
		                    null,
		                     ["text-align:center;",
		                     "text-align:center;",
		                     "text-align:center;",
		                     "text-align:center;",
		                     "text-align:center;",
		                     "text-align:center;"]);
		rol.grid.attachHeader("#rspan,&nbsp;,"+
				"<input id='sr_hfrolename' type='text' style='width:90%'/>,"+
				"<input id='sr_hfroledesc' type='text' style='width:90%'/>,"+
				"#rspan,#rspan");
		rol.grid.setInitWidths("40,100,200,270,125,125");
		rol.grid.setColumnIds("ROW_NO,ROLE_ID,ROLE_NAME,ROLE_DESC,CREATOR,CREATE_TIME");
		rol.grid.setColTypes("ro,ro,ro,ro,ro,ro");
		rol.grid.setColSorting("na,str,str,str,str,str");
		rol.grid.setColumnsVisibility("false,true,false,false,false,false");
		rol.grid.setColAlign("center,left,left,left,center,center");
		rol.grid.setEditable(false);
		rol.grid.setLang(fmd.lang);
		rol.grid._grid_ordercolumns = [{"CREATE_TIME":"DESC"}];
		rol.grid.init();
		
		//paging
		rol.grid.setPagingWTMode(true,true,true,[10,20,50]);
		rol.grid.enablePaging(true,10,5,'id_paging_selectHideForRole');
		rol.grid.setPagingSkin("toolbar", dhx_skin);
		
		rol.grid.attachEvent("onPageChanged", function(ind,fInd,lInd){
			quri_toPage(fInd+1, lInd);
		});
		//header click event
		rol.grid.attachEvent("onHeaderClick", grid_onHeaderClick);
		
		rol.grid.attachEvent("onRowDblClicked", function(rid,cid){
			rtnValue(rid);
		});
		
		fm2.attachEvent("onButtonClick", function(btid) {
			if (btid=='fb_ok') {
				var rid = rol.grid.getSelectedRowId();
				if (!rid) {
					msg(fmd_i18n_msg_sel);
					return;
				}
				rtnValue(rid);
			}
		});

		quri_toPage(1, 10);
		
		//return
		function rtnValue(rid) {
			var ri = rol.grid.cells(rid, 1).getValue();
			var rn = rol.grid.cells(rid, 2).getValue();
			var rd = rol.grid.cells(rid, 3).getValue();
			var rtnObj = [{"realValue":ri, "displayValue":rn, "roleDesc":rd}];
			var newval = {"roles": rtnObj, 
					"displayValue" : rtnObj[0].displayValue+(rtnObj.length>1?"...":"")};
			fmdc.grid_prop.cells(rId, cId).setValue(newval, true);
			w1.close();
		}
		
		//bind header query action
		var trsr_versionname = $("#sr_hfrolename").parents('tr:first');
		trsr_versionname.find('td').bind('click',utp_stopEvent);
		trsr_versionname.find('td').bind('mouseover',utp_stopEvent);
		$("#sr_hfrolename").bind('keypress', rol_enterQuery);
		$("#sr_hfroledesc").bind('keypress', rol_enterQuery);
		
		function rol_enterQuery(e) {
			if (e.keyCode==13) {
				rol.boquery_boname = $.trim($("#sr_hfrolename").val());
				rol.boquery_bodesc = $.trim($("#sr_hfroledesc").val());
				rol.grid.currentPage = 1;
				quri_toPage(1, 10);
			}
		}
		
		//stop event propagation
		function utp_stopEvent(e){
			if (e && e.stopPropagation!=undefined) {
				e.stopPropagation();
			} else if (window.event){
				window.event.cancelBubble = true;
			}
			return false;
		}
		
		//query
		function quri_toPage(fromRow, toRow){
			lo1.cells('b').progressOn();
			var p = {"queryParams":{}, "fromRow":fromRow, "toRow":toRow, 
					"timezoneOffset":new Date().getTimezoneOffset(),
					"ordercolumns":JSON.stringify(rol.grid._grid_ordercolumns)};
			rol.boquery_boname && (p.queryParams.roleName = rol.boquery_boname);
			rol.boquery_bodesc && (p.queryParams.roleDesc = rol.boquery_bodesc);
			p.queryParams.roleType='1';
			p.queryParams = JSON.stringify(p.queryParams);
			doPostAsyncJson(rol.rest_query, p,
					function(ret) {
						if (!ret) {
							lo1.cells('b').progressOff();
							msgErr(fmd_i18n_msg_readfail);
							return;
						}
						rol.grid.clearAllInPaging();
						rol.grid.parse(ret, "json");
						lo1.cells('b').progressOff();
					}, 
					function() {
						lo1.cells('b').progressOff();
						msgErr(fmd_i18n_msg_readfail);
					});
			
		}
	}
	
	fmdmeta_prop.func.selectHideForUrl = function(rId, cId) {
		$("#popupselector iframe#popupselectorFrame").attr("src",
				(fmd.bpmpCtx=='/' ? '' : fmd.bpmpCtx) + fmd.roleselurl);
		$("#popupselector").dialog({
			width : 600,
			height : 480,
			modal : true,
			draggable: false,
			resizable : false,
			buttons : {
				Ok : function() {
					var rtnObjStr = window.frames["popupselectorFrame"].returnValue();
					//console.log(rtnObjStr);
					if (!rtnObjStr) return;
					var rtnObj = JSON.parse(rtnObjStr);
					if (rtnObj && rtnObj.length>0) {
						var newval = {"roles":rtnObj, 
								"displayValue" : rtnObj[0].displayValue+(rtnObj.length>1?"...":"")};
						fmdc.grid_prop.cells(rId, cId).setValue(newval, true);
					}
					$( this ).dialog( "close" );
				},
				Cancel : function() {
					$( this ).dialog( "close" );
				}
			}
		});
	}
	
	fmdmeta_prop.func.clearHideFor = function(rId, cId) {
		fmdc.grid_prop.cells(rId, cId).setValue(null, true);
	};
	
	
	//================== after fmdf_initComponentMeta
	
	//未指定属性则不提供权限过滤功能
	if (!fmd.roleselrest && !fmd.roleselurl) {
		delete fmdmeta_prop.common.datacontrol.properties.hidefor;
	}
}



